//
//  MYGResumeEditEducationView.swift
//  MYDoctor
//
//  Created by 小火科技 on 2024/4/12.
//

import UIKit

class MYGResumeEditEducationView: UIView {
    var selectTypeBlock:((_ index:Int)->Void)?
    var index: Int = 0
    private var contents:[[String:String]] = [[:]]
    // MARK: - init
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contents = [["icon":"re_qn","title":"荣誉"],["icon":"re_zn","title":"专利"],["icon":"re_sn","title":"出版"],
                                     ["icon":"re_bn","title":"文献"],["icon":"re_dn","title":"专业擅长"],["icon":"re_mn","title":"自定义"]]
       
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK: - UI
    private func configUI() {
        backgroundColor = .white
        
        addSubview(collectionview)
        collectionview.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
    } 
    
    lazy var collectionview: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.minimumLineSpacing = SCALEWIDTH(15)
        layout.sectionInset = UIEdgeInsets(top: 0, left: SCALEWIDTH(27.5), bottom: 0, right: SCALEWIDTH(27.5))
        layout.minimumInteritemSpacing = SCALEWIDTH(32)
        layout.itemSize = CGSize(width: SCALEWIDTH(56), height: SCALEWIDTH(70))
        let collV = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
        collV.showsVerticalScrollIndicator = false
        collV.showsHorizontalScrollIndicator = false
        collV.register(MYGMyPageCollectionViewCell.self, forCellWithReuseIdentifier: "MYGMyPageCollectionViewCell")
        collV.isScrollEnabled = false
        collV.dataSource = self
        collV.delegate = self
        collV.backgroundColor = .clear
        return collV
    }()
    

}
extension MYGResumeEditEducationView:UICollectionViewDelegate,UICollectionViewDataSource {
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        6
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        return CGSize(width: screenWidth, height: SCALEWIDTH(60))
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MYGMyPageCollectionViewCell", for: indexPath) as! MYGMyPageCollectionViewCell
        cell.titleLab.text = contents[indexPath.row]["title"]
        
        let name:String = contents[indexPath.row]["icon"]!
        let imageName:String = "\(name)s"
        cell.titleImageV.image =  index == indexPath.row ? UIImage(named: imageName) : UIImage(named: name)
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
        self.index = indexPath.row
        collectionView.reloadData()
        selectTypeBlock?(index)
    }
    
    
}
